//页面缓存对象
var cache = {};

$(function() {
	initShopSelecter();
	$('.doubledate').kuiDate({
		className : 'doubledate',
		isDisabled : "1" 
	});
});

/**
 * 初始化店面选择器
 */
function initShopSelecter() {
	refreshInput($(".serWrapper"));
	$("#shopIsChoosed").removeAttr("checked");
	$("#shopName").attr("disabled", "disabled");

	$("#shopIsChoosed").bind("click", function() {
		var checked = $(this).attr("checked");
		if (checked) {
			$("#shopName").removeAttr("disabled");
		} else {
			$("#shopName").attr("disabled", "disabled");
			$("#shopName").empty();
		}
	});
}

/**
 * 点击查询按钮
 */
function search() {

	var heads = ["customerName", "mp", "memberCardNo", "carTypeName", "license", "startDate", "endDate"];
	var ids = [];
	for (var i = 0; i < heads.length; i++) {
		ids[i] = 's_' + heads[i];
	}
	heads.push("shopId");
	ids.push("shopName");
	var data = qmsk.collectionData(heads, ids);

	cache.pagination = new Pagination({
		url : '../customer/find/list',
		data : data,
		success : function(rst) {
			var response = new qmsk.Response(rst);
			//"customerId","memberId","isMember","memberCardNo","shopId",
			//"customerName","license","brandName","carSystemName",
			//"carTypeName","levelName","integralAmount","depositAmount",
			//"cashCouponAmount","couponAmount","discount","status"
			qmsk.dataTable({
				tbodyId : 'customerTbody',
				heads : ["customerId", "customerName", "mp", "license", "brandName", "carSystemName", "carTypeName", "memberCardNo", "levelName", "depositAmount", "createFileTime", "shopName", ["customerId", "memberCardNo", "memberId", "shopId"]],
				response : response,
				sup : ['sup', '共 [index] 条'],
				handler : [[12, detailHandler]]
			});

		},
		pagerHandler : 'pager'
	});

}

function detailHandler(customerId, memberCardNo, memberId, shopId, row) {

	var html = '';

	if (qmsk.isEmpty(memberCardNo) || qmsk.isEmpty(memberId)) {
		html = "<input type='button' class='common_btn' value='详情' onClick='toDetail(" + customerId + ")'/>";
	} else {
		html = "<input type='button' class='common_btn' value='详情' onClick='toDetail(" + customerId + ",\"" + memberCardNo + "\"," + memberId + "," + shopId + ")'/>";
	}

	return html;
}

function toAddPage() {
	qmsk.redirectUrl("ownerCreate.html");
}

function toDetail(customerId, memberCardNo, memberId, shopId) {
	qmsk.redirectUrl("owner.html", {
		customerId : customerId,
		memberCardNo : memberCardNo,
		memberId : memberId,
		shopId : shopId
	});
}

